<?php

use mdm\admin\AnimateAsset;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\YiiAsset;
use yii\widgets\DetailView;

/* @var $this yii\web\View */
/* @var $model mdm\admin\models\AuthItem */
/* @var $context mdm\admin\components\ItemController */

$context = $this->context;
$labels = $context->labels();
$this->title = '角色';
if( $labels['Items'] == 'Permissions'){
    $this->title = '权限';
}

$this->params['breadcrumbs'][] = ['label' => $this->title, 'url' => ['index']];
$this->params['breadcrumbs'][] = $model->name;

AnimateAsset::register($this);
YiiAsset::register($this);
$items = $model->getItems();
if($this->title == '权限'){
    $items['available'] = array_diff($items['available'],['permission']);
    $items['assigned'] = array_diff($items['assigned'],['permission']);
}
if($this->title == '角色'){
    $items['available'] = array_diff($items['available'],['route']);
    $items['assigned'] = array_diff($items['assigned'],['route']);
}
$items['available'] = array_diff($items['available'],['role']);
$items['assigned'] = array_diff($items['assigned'],['role']);

$opts = Json::htmlEncode([
    'items' => $items,
]);
$this->registerJs("var _opts = {$opts};");
$this->registerJs($this->render('_script.js'));
$animateIcon = ' <i class="glyphicon glyphicon-refresh glyphicon-refresh-animate"></i>';
?>
<div class="auth-item-view">
    <h1>
        给“<?=$model->name?>”<?=Html::encode($this->title);?>绑定<?=$labels['Items'] == 'Permissions' ? "路由" : "权限" ?>
    </h1>


    <div class="row">
        <div class="col-sm-5">
            <input class="form-control search" data-target="available"
                   placeholder="<?=Yii::t('rbac-admin', '查找可绑');?>">
            <select multiple size="20" class="form-control list" data-target="available"></select>

        </div>
        <div class="col-sm-1">
            <br><br>
            <?=Html::a('&gt;&gt;' . $animateIcon, ['assign', 'id' => $model->name], [
    'class' => 'btn btn-success btn-assign',
    'data-target' => 'available',
    'title' => Yii::t('rbac-admin', 'Assign'),
]);?><br><br>
            <?=Html::a('&lt;&lt;' . $animateIcon, ['remove', 'id' => $model->name], [
    'class' => 'btn btn-danger btn-assign',
    'data-target' => 'assigned',
    'title' => Yii::t('rbac-admin', 'Remove'),
]);?>
        </div>
        <div class="col-sm-5">
            <input class="form-control search" data-target="assigned"
                   placeholder="<?=Yii::t('rbac-admin', '查找已绑');?>">
            <select multiple size="20" class="form-control list" data-target="assigned"></select>
        </div>
    </div>
</div>
